<template>
  <div id="shop">
    <div
      class="header"
      :style="{
        backgroundImage: `url(${
          shopinfo.info && shopinfo.info.poi_back_pic_url
        })`,
      }"
    >
      <div @click="back" class="back">&lt;</div>
      <h2>
        {{ shopinfo.info && shopinfo.info.name }}
        <span
          :class="{ save: this.$store.state.savestate == `已收藏!` }"
          @click="save(shopinfo.info.mtWmPoiId)"
          >♥</span
        >
      </h2>
      <span><input type="text" placeholder="搜索" /></span>
      <span>点餐</span>
      <span>评价{{ shopinfo.info && shopinfo.info.wmPoiScore }}</span>
      <span>商家</span>
    </div>
    <div class="centerbox">
      <div class="navlist">
        <div
          @click="state(index)"
          v-for="(item, index) in shopinfo.taglist"
          :key="index"
          :class="{ active: nowindex == index }"
        >
          <span>{{ item.name }}</span>
        </div>
      </div>
      <div class="goodslist">
        <p>热销</p>
        <div
          class="goodbox"
          v-for="(item, index) in shopinfo.info &&
          shopinfo.taglist[nowindex].goodlist"
          :key="index"
        >
          <div class="pic">
            <img :src="item.picture" alt="" />
          </div>
          <div class="right">
            <div class="text">
              <div class="name">{{ item.name }}</div>
              <div class="intro">{{ item.month_saled_content }}</div>
            </div>
            <div class="money-add">
              <div class="money">￥{{ item.min_price }}</div>
              <div class="add">＋</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footerbox">
      <span class="pres">￥528</span>
      <button>去结算</button>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { shop } from "../api";
import { Toast } from "vant";

Vue.use(Toast);
export default {
  mounted() {
    // console.log(this.$route.params);
    shop(this.$route.params).then((res) => {
      this.shopinfo = res.data.shopinfo;
      console.log(this.shopinfo);
    });
  },
  data() {
    return {
      shopinfo: {},
      nowindex: 0,

    };
  },
  methods: {
    state(index) {
      this.nowindex = index;
    },
    back() {
      this.$router.go(-1);
    },
    save(shopid) {
      // console.log(shopid);
      if (this.$store.state.savestate == "已收藏!") {
        this.$store.commit("unsave", { userid: localStorage.getItem('id'), shopid: shopid });
        Toast({
          message: "取消收藏",
          icon: "like-o",
        });
      } else {
        this.$store.commit("save", { userid: localStorage.getItem('id'), shopid: shopid });

        Toast({
          message: "收藏成功",
          icon: "like-o",
        });
      }
    },
  },
};
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
}
#shop {
  height: 100%;
  display: flex;
  flex-direction: column;
}
#shop .back {
  font-size: 30px;
  color: lightskyblue;
}
.header {
  font-weight: 700;
  background-size: cover;
}
.header h2 {
  margin-bottom: 30px;
}
.header h2 span {
  float: right;
  color: white;
}
.header h2 span.save {
  color: red;
}
.header span {
  margin-right: 20px;
  height: 30px;
  display: inline-block;
}
.header span:nth-child(3) input {
  width: 30px;
  height: 20px;
  border-radius: 30px;
  padding-left: 20px;
  border: none;
  background-color: rgb(238, 237, 237);
}
.header span:nth-child(4) {
  color: lightskyblue;
  border-bottom: 2px solid lightskyblue;
}
.centerbox {
  flex: 1;
  display: flex;
  border-top: 1px solid rgb(240, 239, 239);
  margin-top: 5px;
}
.centerbox .navlist {
  width: 25%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.centerbox .navlist div {
  box-sizing: border-box;
  padding: 0 10px;
  margin: 10px 0 0px 2px;
  height: 60px;
  text-align: center;
}
.centerbox .navlist div.active {
  border-left: 2px solid red;
  font-weight: 700;
  margin-left: 0;
}

.centerbox .goodslist p {
  line-height: 40px;
  font-weight: 700;
  font-size: 14px;
}
.centerbox .goodslist .goodbox {
  margin: 0 10px 10px 0;
  display: flex;
}
.centerbox .goodslist .goodbox .pic {
  width: 100px;
}
.centerbox .goodslist .goodbox .pic img {
  width: 100%;
}
.centerbox .goodslist .goodbox .right {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.centerbox .goodslist .goodbox .text .name {
  font-size: 14px;
  font-weight: 800;
}
.centerbox .goodslist .goodbox .text .intro {
  font-size: 12px;
  color: gray;
}
.centerbox .goodslist .goodbox .text {
  margin-left: 10px;
}
.centerbox .goodslist .goodbox .money-add {
  display: flex;
  justify-content: space-between;
  margin-left: 10px;
}
.centerbox .goodslist .goodbox .money-add .money {
  font-size: 14px;
  color: red;
  font-weight: 800;
}
.centerbox .goodslist .goodbox .money-add .add {
  text-align: center;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  border: 0;
  margin-left: 90px;
  color: white;
  background-color: lightskyblue;
}
.footerbox {
  height: 70px;
  background-color: rgba(101, 106, 111, 0.925);
  position: fixed;
  bottom: 0;
  width: 100%;
}
.footerbox span {
  display: inline-block;
  margin: 5px 50px;
  color: white;
}
.footerbox button {
  float: right;
  margin: 5px;
  padding: 10px 30px;
  border-radius: 10px;
  border: none;
  background-color: lightgreen;
  color: white;
}
</style>